package top.chatgqt.SmartChargeStation.demo.netty.handlers;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import lombok.extern.slf4j.Slf4j;

/**
 * 粘包半包场景复现（客户端）
 */
@Slf4j
public class ImoocClientPkgHandler extends SimpleChannelInboundHandler<String> {

    // 连接建立触发
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        int count=0;
        for(int i=0;i<100;i++) {
            String str="hello world$_";
            ++count;
            ctx.writeAndFlush(str);
            log.info("粘包半包>>>>count：{}次发送数据包", count);
        }
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {

    }
}
